package com.xyy.ec.pop.erp.hx.utils.http;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okio.Buffer;

import java.io.IOException;

public class CommonInterceptor implements Interceptor {
    private final String mApiKey;
    private final String mApiSecret;

    public CommonInterceptor(String apiKey, String apiSecret) {
        mApiKey = apiKey;
        mApiSecret = apiSecret;
    }

    public Response intercept(Chain chain) throws IOException {
        Request oldRequest = chain.request();

        Request.Builder newRequestBuild=null;
        newRequestBuild = oldRequest.newBuilder();
        Request newRequest = newRequestBuild
                .addHeader("Content-Type", "application/octet-stream;charset=utf-8")
                .build();

        return chain.proceed(newRequest);
    }
    private static String bodyToString(final RequestBody request) {
        try {
            final RequestBody copy = request;
            final Buffer buffer = new Buffer();
            if (copy != null)
                copy.writeTo(buffer);
            else
                return "";
            return buffer.readUtf8();
        } catch (final IOException e) {
            return "did not work";
        }
    }

}
